package com.ruoyi.fjtseac.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.xss.Xss;
import com.ruoyi.common.xss.XssValidator;
import com.ruoyi.fjtseac.domain.dto.ApplicationFormDto;
import com.ruoyi.fjtseac.domain.po.ApplicationForm;
import com.ruoyi.fjtseac.util.aop.RedisCacheClear;
import com.ruoyi.fjtseac.util.aop.RedisCacheEnable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fjtseac.service.ApplicationFormService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 志愿者申请Controller
 *
 * @author ruoyi
 * @date 2022-
 */
@RestController
@RequestMapping("/system/form")
@Api(tags = {"志愿者申请接口"})
public class ApplicationFormController extends BaseController {
    @Autowired
    private ApplicationFormService applicationFormService;

    /**
     * 查询志愿者申请列表
     */
    //@PreAuthorize("@ss.hasPermi('fjtseac:form:list')")
    @GetMapping("/list")
    @ApiOperation("志愿者申请列表")
    public TableDataInfo list(ApplicationFormDto applicationFormDto) {
        startPage();
        List<ApplicationForm> list = applicationFormService.selectApplicationFormList(applicationFormDto);
        return getDataTable(list);
    }

    /**
     * 导出志愿者申请列表
     */

    @PreAuthorize("@ss.hasPermi('fjtseac:form:export')")
    @PostMapping("/export")
    @ApiOperation("志愿者申请列表导出")
    public void export(HttpServletResponse response, ApplicationFormDto applicationFormDto) {
        List<ApplicationForm> list = applicationFormService.selectApplicationFormList(applicationFormDto);
        ExcelUtil<ApplicationForm> util = new ExcelUtil<ApplicationForm>(ApplicationForm.class);
        util.exportExcel(response, list, "志愿者申请数据");
    }

    /**
     * 获取志愿者申请详细信息
     */
    @ApiOperation("志愿者申请个人详细信息")
    @PreAuthorize("@ss.hasPermi('fjtseac:form:getInfo')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(applicationFormService.selectApplicationFormById(id));
    }

    /**
     * 新增志愿者申请(小程序端申请志愿者)
     */
    @PostMapping
    @ApiOperation("志愿者申请")
    public AjaxResult add(@RequestBody @Validated ApplicationFormDto applicationFormDto) {
        return applicationFormService.insertApplicationForm(applicationFormDto);
    }

    /**
     * 修改志愿者申请
     */

    @PreAuthorize("@ss.hasPermi('fjtseac:form:edit')")
    @PutMapping
    @ApiOperation("志愿者申请信息编辑")
    public AjaxResult edit(@RequestBody ApplicationFormDto applicationFormDto) {
        return toAjax(applicationFormService.updateApplicationForm(applicationFormDto));
    }

    /**
     * 删除志愿者申请
     */

    @PreAuthorize("@ss.hasPermi('fjtseac:form:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("志愿者申请删除")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(applicationFormService.deleteApplicationFormByIds(ids));
    }

    /**
     * 拒绝志愿者申请
     *
     * @param applicationFormDto
     * @return
     */

    @PreAuthorize("@ss.hasPermi('fjtseac:form:refuse')")
    @GetMapping("/refuse")
    @ApiOperation("志愿者申请拒绝")
    public AjaxResult refuse(ApplicationFormDto applicationFormDto) {
        return applicationFormService.refuse(applicationFormDto);
    }

    /**
     * 返回拒绝理由
     *
     * @return
     */

    @GetMapping("/return")
    @ApiOperation("志愿者申请拒绝理由")
    public AjaxResult returnReason(String phone) {
        return applicationFormService.returnReason(phone);
    }

    /**
     * 根据openId返回对应的信息
     *
     * @param openId
     * @return
     */
    @GetMapping("/selectByOpenId")
    @ApiOperation("志愿者个人审核信息")
    public AjaxResult selectByOpenId(String openId) {
        return applicationFormService.selectOneByOpenId(openId);
    }
}
